/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.interpreter.backends.rdf;

/**
 *
 * @author Laurent WOUTERS
 */
public class RDFLiteralNode implements RDFNode {
    private xowl.lang.runtime.Literal literal;

    public xowl.lang.runtime.Literal getLiteral() { return literal; }
    @Override public RDFNodeType getNodeType() { return RDFNodeType.Literal; }

    public RDFLiteralNode(xowl.lang.runtime.Literal lit) { literal = lit; }

    @Override public int hashCode() { return literal.getLexicalValue().hashCode(); }
    @Override public boolean equals(Object obj) {
        if (obj instanceof RDFLiteralNode)  {
            RDFLiteralNode node = (RDFLiteralNode)obj;
            return (literal.getLexicalValue().equals(node.literal.getLexicalValue()) && literal.getMemberOf() == node.literal.getMemberOf());
        }
        return false;
    }
    
    @Override public String toString() {
        java.lang.StringBuilder builder = new java.lang.StringBuilder("\"");
        builder.append(literal.getLexicalValue());
        builder.append("\"");
        if (literal.getMemberOf() != null) {
            builder.append("^^");
            builder.append(literal.getMemberOf().getInterpretationOf().getHasIRI().getHasValue());
        }
        return builder.toString();
    }
}
